package com.hyl.exam.controller;

import com.example.exam.pojo.TestPaper;
import com.example.exam.pojo.User;

import com.hyl.exam.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @author
 * @date 2023/03/05
 */
@RestController
public class ClientWeb {

    @Autowired
    ClientService clientService;

    /**
     *  查看题目
     */
    @GetMapping("/")
    public Object get(){
        return "123";
    }
    @GetMapping("/getQuestion")
    public Object getQuestion() {
        return clientService.getQuestion();
    }

    /**
     *  查看已经提交的答案
     */
    @GetMapping("/getTestPaper/{tid}")
    public Object getTestPaper(@PathVariable(value = "tid") int tid, HttpServletRequest request) {
        return clientService.getTestPaper(tid) ;
    }

    /**
     *  提交答案
     */
    @PostMapping("/submitTitle")
    public Object submitTitle(@RequestBody TestPaper testPaper, HttpServletRequest request) {

        return clientService.submitTitle(  testPaper);
    }

    /**
     *  预览答案
     */
    @GetMapping("/preview")
    public Object preview(HttpServletRequest request) {
        return clientService.preview(request) ;
    }

    /**
     *  提交试卷
     */
    @PostMapping("/submit")
    public Object submit(HttpServletRequest request) {
        return clientService.submit(request) ;
    }

    /**
     *  查看图片
     */
    @GetMapping("/getPicture/{pictureName}")
    public void getPicture(@PathVariable(value = "pictureName") String pictureName, HttpServletResponse response) throws IOException {
        System.out.println("============图片=============");
        clientService.getPicture( pictureName);
    }

    /**
     *  登录
     */
    @PostMapping("/login")
    public Object login(@RequestBody User user) {
        return clientService.login(user);
    }
}
